﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SingletonPattern
{
    public class user
    {
        public string name { get; set; }
        public int age { set; get; }
    }

    class Home
    {
        private static Home home;
        public static Home GetInstance()
        {
            if (home == null)
            {
                home = new Home();
            }
            return home;
        }



        public List<user> users = null;
        private Home()
        {
            users = new List<user>();
        }


        public void AddUser(user user)
        {
            users.Add(user);
        }

        public void ShowUser()
        {
            foreach (var u in users)
            {
                Console.WriteLine(u.name);
            }

        }

    }


    class Program
    {
        static void Main(string[] args)
        {
            Home home = Home.GetInstance();
            user user1 = new user();
            user1.name = "mama";

            user user2 = new user();
            user2.name = "baba";

            user user3 = new user();
            user3.name = "erzi";

            home.AddUser(user1);
            home.AddUser(user2);
            home.AddUser(user3);
            home.ShowUser();
            Console.WriteLine(home.ToString());
            Console.WriteLine(home.GetHashCode());
            Console.WriteLine("+++++++++++++++");

            Home home2 = Home.GetInstance();
            home2.ShowUser();
            Console.WriteLine(home2.GetHashCode());
            Console.WriteLine("------------");
        }
    }
}
